
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../../common/style/extension_util.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';

import '../../style/app_style.dart';

class ConfirmStyle{
  final double? topTitle;
  TextStyle? titleStyle;
  TextStyle? subtitleStyle;
  OutlinedBorder? cancelBorder;
  OutlinedBorder? sureBorder;
  final TextAlign? textAlign;
  ConfirmStyle.style1({this.topTitle = 20,this.titleStyle,this.textAlign}){
    titleStyle = const TextStyle(color: Color(0xFF121419),fontSize: 19);
    subtitleStyle = const TextStyle(color: Color(0xFF747686),fontSize: 14);
    cancelBorder = const StadiumBorder(side: BorderSide(color: Color(0xFFCACACA),width: 0.5));
    sureBorder = const StadiumBorder();
    // textAlign =
  }
}

class ConfirmWidget extends StatelessWidget {
  final String title;
  final Widget? icon;
  final String? content;
  final bool onlySure;
  final String? subtitle;
  final String? okText;
  final String? cancelText;
  final Function onConfirmation;
  final Function? onCancel;
  final bool showDivider;
  final TextAlign? textAlign;
  final ConfirmStyle? style;
  const ConfirmWidget({
    Key? key,
    required this.title,
    this.content = "",
    this.icon,
    required this.onConfirmation,
    this.subtitle,
    this.okText = "确定",
    this.cancelText,
    this.onlySure = false,
    this.onCancel,
    this.showDivider = true,
    this.textAlign,
    this.style
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
        mainAxisSize: MainAxisSize.min,
        children: [
           SizedBox(
            height: style?.topTitle ?? 10,
          ),
          if (icon != null) icon!,
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 24),
            child: Text(
              title,
              style:  TextStyle(
                color: AppColor.textColor,
                decorationStyle: TextDecorationStyle.dotted,
                fontSize: 16,
              ),
            ),
          ),
          const SizedBox(height: 12,),
          if (content != null && content!.isNotEmpty)
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 24),
              child: Text(
                content!,
                style:  TextStyle(
                  color: AppColor.textColor1,
                  decorationStyle: TextDecorationStyle.dotted,
                  fontSize: 14,
                ),
                textAlign: textAlign,
              ),
            ),
          const SizedBox(
            height: 24,
          ),
          Divider(height: 0.5,color: AppColor.backGroundColor,).addVisibility(showDivider),
          Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              // if (textOnly) const SizedBox(width: 20),
              // if (textOnly)
              Row(children: [
                AppButton.textSizeBtn(() {
                  SmartDialog.dismiss();
                  onCancel?.call();
                }, cancelText ?? "取消",style: AppButtonStyle.textBtn,border: style?.cancelBorder,width: 110),
                Divider(height: 0.5,color: AppColor.backGroundColor,),
                SizedBox(width: 14),
              ],).addVisibility(onlySure),

                AppButton.textSizeBtn(() {
                  SmartDialog.dismiss();
                  onConfirmation();
                }, okText,width: 110).addContainer(border: style?.sureBorder),
            ],
          ),
          const SizedBox(
            height: 26
          ),
        ],
      ).addContainer(margin: const EdgeInsets.fromLTRB(40, 0, 40, 0));
  }
}


class BottomDialog extends StatelessWidget {
  final String title;
  final Widget? icon;
  final String? content;
  final bool onlySure;
  final String? subtitle;
  final String? okText;
  final String? cancelText;
  final Function onConfirmation;
  final Function? onCancel;
  final bool showDivider;
  final TextAlign? textAlign;
  final ConfirmStyle? style;
  const BottomDialog({
    Key? key,
    required this.title,
    this.content = "",
    this.icon,
    required this.onConfirmation,
    this.subtitle,
    this.okText = "确定",
    this.cancelText,
    this.onlySure = false,
    this.onCancel,
    this.showDivider = true,
    this.textAlign,
    this.style
  }) : super(key: key);
  @override
  Widget build(BuildContext context) {
     return Column(
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        SizedBox(
          height: style?.topTitle ?? 20.h,
        ),
        if (icon != null) icon!,
        Padding(
          padding:  EdgeInsets.symmetric(horizontal: 20.w),
          child: Text(
            title,
            style:  AppStyle.textStyle
          ),
        ),
        if (content != null && content!.isNotEmpty)
          Padding(
            padding:  EdgeInsets.symmetric(horizontal: 20.w,vertical: 5.w),
            child: Text(
              content!,
              style:  TextStyle(
                color: AppColor.textColor1,
                decorationStyle: TextDecorationStyle.dotted,
                fontSize: 14,
              ),
              textAlign: textAlign,
            ),
          ),
        SizedBox(
          height: 30.h,
        ),
        Divider(height: 0.5,color: AppColor.backGroundColor,).addVisibility(showDivider),
        Row(

          children: [
            // if (textOnly) const SizedBox(width: 20),
            // if (textOnly)
            AppButton.fullBtn(() {
              SmartDialog.dismiss();
              onCancel?.call();
            },cancelText ?? "cancel".tr,style: AppButtonStyle.hollowBlack,padding:EdgeInsets.only(left: 20.w)).addVisibility(onlySure).addExpand(),
            SizedBox(width: 15.w),
            AppButton.fullBtn(() {
              SmartDialog.dismiss();
              onConfirmation();
            }, okText,padding: EdgeInsets.only(right: 20.w)).addExpand(),
          ],
        ),
        const SizedBox(
            height: 26
        ),
      ],
    ).addContainer();
  }
}
